from flask import request
from SQLOperation.PatientSQLOperation import PatientSQLOperation
from SQLConfig import app


@app.route('/searchPatient', methods=['Get', 'POST'])
def searchPatient():  # put application's code here
    """
    搜索病人
    """
    name = request.json.get("name")
    phone = request.json.get("phone")
    patient = PatientSQLOperation.search(name, phone)
    if patient is None:
        return "patient not exist"
    else:
        # 解析数据，返回json格式
        return {
            "name": patient.name
            , "gender": patient.gender
            , "age": patient.age
            , "time": patient.time
            , "phone": patient.phone
        }
